﻿<script type="text/javascript" src="../../Scripts/jquery.fileupload.js"></script>

<div class="spacer"></div>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
    <div class="spacer"></div>
    <label>Select Introducer</label>
    @Html.DropDownList("CallCentreID")    
    <div>
    <label>Select Campaign Type</label>
        @Html.DropDownList("SectorID")
    </div>
    <div class="spacer"></div>
    <div>
    <label>Select File To Upload</label>
    <span style="font-size: 0px;" class="btn btn-success fileinput-button" id="spanupload">
	    <i class="glyphicon glyphicon-plus"></i>
	    <span>Upload Import File</span>
	    <input class="fileupload" id="fileupload" type="file" name="files[]" ></span>
    </div>

    <label id="lblfilename"></label>
    <input type="hidden" id="hdnFileName" name="hdnFileName" />

    <div class="progress">
	    <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
		    <span class="sr-only">0% Complete</span>
	    </div>
    </div>    
    <div>
    <div class="spacer"></div>
    <input type="submit" id="buttonProcess" value="Process Import" />
    </div>
    </fieldset>
}

<script type="text/javascript">

    $('.fileupload').fileupload({
        dataType: 'json',
        url: '/Leads/UploadFile',
        autoUpload: true,
        done: function (e, data) {
            $.ajax({
                url: "/Leads/RegisterFile",
                type: "POST",
                data: {
                    id: $(this).data("leadresultsid"),
                    filename: data.result.name
                }
            });
            $('#lblfilename').text("File Uploaded : " + data.result.name);
            $('#hdnFileName').val(data.result.name);
        }
    }).on('fileuploadprogressall', function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('.progress .progress-bar').css('width', progress + '%');
    });

    $("#buttonProcess").click(function () {
        $(this).val("Processing....Please Wait");
        return true;
    });

</script>